package com.sc.VenusQueryBeta.model.sqlite;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;

import com.hengjun.kingstar.sdk.utils.LogUtil;

/**
 * Created by Administrator on 20/11/2018.
 * 数据库操作类
 */

public class DatabaseHelper extends SQLiteOpenHelper {
    private volatile static DatabaseHelper uniqueInstance;

    private DatabaseHelper(Context context, String name, int version) {
        super(context, name, null, version);//第三个参数CursorFactory指定在执行查询时获得一个游标实例的工厂类,设置为null,代表使用系统默认的工厂类
    }

    public static DatabaseHelper getInstance(Context context, String name, int version) {
//        if (uniqueInstance == null) {
//            LogUtil.e("uniqueInstance = null");
//            synchronized (DatabaseHelper.class) {
//                if (uniqueInstance == null) {
                    uniqueInstance = new DatabaseHelper(context, name, version);
//                }
//            }
//        }
//        LogUtil.e("uniqueInstance not null");
        return uniqueInstance;
    }

    @Override
    public void onCreate(SQLiteDatabase db) {
        db.execSQL("CREATE TABLE IF NOT EXISTS messages (mIndex INTEGER PRIMARY KEY AUTOINCREMENT,linkmanID" +
                " text,sendClientIndex text, receiveClientIndex text,messageContent text,sendTime text,isRead bit," +
                "sendAreaCode text,receiveAreaCode text,sendId text,receiveId text,messageIndex text,voicePath text," +
                "voiceTime text,isListened bit,messageType integer,sendStatus integer,resourcePath text)");

        db.execSQL("CREATE TABLE IF NOT EXISTS reads (mIndex INTEGER PRIMARY KEY AUTOINCREMENT,linkmanID" +
                " text,sendClientIndex text, receiveClientIndex text,messageContent text,sendTime text,isRead bit," +
                "sendAreaCode text,receiveAreaCode text,sendId text,receiveId text,messageIndex text,voicePath text," +
                "voiceTime text,isListened bit,messageType integer,sendStatus integer,resourcePath text)");
    }

    @Override
    public void onUpgrade(SQLiteDatabase sqLiteDatabase, int i, int i1) {

    }
}
